home *** CD-ROM | disk | FTP | other *** search
- /* *************************************************************** */
- /* Mini - ftp */
- /* Sample app for Tcp4w.Dll: This program establishes a connection */
- /* waits for incoming frame then sends a QUIT command and exits */
- /* *************************************************************** */
-
- #define STRICT +
- #include <windows.h>
- #include <string.h>
- #include <tcp4w.h>
-
- #define MBox(sz) MessageBox (NULL, sz, "Mini_ftp", MB_OK)
-
-
- int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpszCmdLine, int cmdShow)
- {
- int Rc;
- char sz [256];
- char szTcp[128];
- SOCKET ConnSock=INVALID_SOCKET;
-
- /* gets version of DLL */
- Tcp4uVer (sz, sizeof sz);
- MBox (sz);
-
- /* checks if first parameter OK */
- if (lpszCmdLine==NULL || lpszCmdLine[0]==0)
- {
- MBox ("Usage: Mini_ftp <Host>");
- return 0;
- }
-
-
- /* Inits winsocket use */
- Rc= Tcp4uInit ();
- if (Rc!=TCP4U_SUCCESS)
- {
- MBox ("Erreur in Init");
- return 0;
- }
-
- /* Establishes the connection */
- Rc = TcpConnect (& ConnSock, lpszCmdLine, "ftp", NULL);
- if (Rc!=TCP4U_SUCCESS)
- {
- MBox (Tcp4uErrorString (Rc));
- return 0;
- }
-
- /* Waits 30sec for incoming message */
- memset (szTcp, 0, sizeof szTcp);
- Rc = TcpRecv (ConnSock, szTcp, sizeof szTcp - 1, 30, HFILE_ERROR);
- /* if TcpRecv successful, Rc is the number of received bytes */
- /* thus test if Rc below TCP4U_SUCCESS */
- if (Rc<TCP4U_SUCCESS)
- {
- lstrcpy (sz, "Reception Error:\n");
- lstrcat (sz, Tcp4uErrorString (Rc));
- }
- else
- {
- lstrcpy (sz, "Reception OK. Host answered:\n\n");
- lstrcat (sz, szTcp);
- }
-
- /* sends the Quit command with Telnet functions */
- TnSend (ConnSock, "QUIT", FALSE, HFILE_ERROR);
-
- /* closes connection without waiting for server's answer */
- TcpClose (&ConnSock);
-
- /* Releases Tcp4w resources */
- Tcp4uCleanup ();
-
- /* Displays server message */
- if (sz[0]!=0) MBox (sz);
-
- return 0;
- } /* WinMain */
-